﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.Model;
using SMTC.Dao.BaseInfo;
using SMTC.BO.Common;

namespace SMTC.BO.BaseInfo
{
    public class ProductBaseInfoServices
    {
        private ProductBaseInfoDao _dao = new ProductBaseInfoDao();

        /// <summary>
        /// 获取产品信息列表
        /// </summary>
        /// <param name="ProductCode"></param>
        /// <param name="HalfProductCode"></param>
        /// <returns></returns>
        public List<SMT_ProductBaseInfoModel> GetProductBaseList(string ProductCode)
        {
            ProductCode = DbValueProccess.StrProccess(ProductCode);

            return _dao.GetProductBaseList(ProductCode);
        }

        public bool InsertOrUpdate(SMT_ProductBaseInfoModel model)
        {

            if (_dao.GetProductBaseByProduct(model.ProductCode) != null)
            {
                if (string.IsNullOrEmpty(model.ProductCode))
                {
                    return false;
                }
                else
                {
                    return _dao.UpdateProductBase(model);
                }

            }
            else
            {
                return _dao.InsertProductBase(model);
            }

        }

        public bool InsertOrUpdateForHalfProduct(SMT_ProductBaseInfoModel model)
        {

            if (_dao.GethalfProductBaseByProduct(model.HalfProductCode) != null)
            {
                return _dao.UpdateHalfProductBase(model);
            }
            else
            {
                return _dao.InsertHalfProductBase(model);
            }

        }

        public bool DeleteProduct(string ID)
        {
            return _dao.DeleteProductBase(ID);
        }

        public List<SMT_ProductBaseInfoModel> getProduct(string product)
        {
            return _dao.getProduct(product);
        }
    }
}
